home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr51 / postalbc.zip / POSTALBC.1 < prev    next >
Text File  |  1993-04-17  |  3KB  |  64 lines

  1. *  postalbc.1  Version 1.0  Released 03-Jul-91
  2.  
  3.  
  4. * DOC
  5. *      Routine:PostalBC
  6. *   Parameters:string zipcode
  7. *              either 5 digit or 9 digit with or without a "-"
  8. *        Usage:do PostalBC with "24551"
  9. *       Author:David G. Frankenbach, 804-237-2342, A-TBBS (FRNKNBCH)
  10. *  Description:This routine will print a Postal Bar Code using HP PCL
  11. *              This routine does no error checking on the zipcode passed in
  12. *     Revision:03-Jul-91 Initial Release
  13. procedure PostalBC
  14. parameter zip_code
  15. private all_codes, bar_code, check, i, j, length, zip_digit
  16.  
  17. all_codes = "11000 00011 00101 00110 01001 01010 01100 10001 10010 10100"
  18.  
  19. bar_code = "1"                                                 && initial frame bar
  20.  
  21. length = len( zip_code )                                       && number of digits in zip
  22. i = 1                                                          && digit index
  23. check = 0                                                      && check digit
  24. do while ( i <= length )                                       && while digits left in string
  25.    zip_digit = substr( zip_code, i, 1 )                        && get this digit
  26.    if ( zip_digit <> "-" )                                     && ignore if -
  27.       j = val( zip_digit )                                     && convert to numeric
  28.       check = check + j                                        && add to check digit
  29.       bar_code = bar_code + substr( all_codes, j * 6 + 1, 5 )  && concat this digit's bit pattern
  30.    endif
  31.    i = i + 1                                                   && next digit
  32. enddo
  33. j = 10 - mod( check, 10 )
  34. bar_code = bar_code + substr( all_codes, j * 6 + 1, 5 )        && concat check digit bit pattern
  35.  
  36. bar_code = bar_code + "1"                                      && terminal frame bar
  37. do PostalBC_Line with bar_code                                 && print the bar code
  38. return
  39.  
  40.  
  41. * DOC
  42. *      Routine:PostalBC_Line
  43. *   Parameters:string bar_code
  44. *        Usage:internal routine, not called by user
  45. *  Description:Print the composed postal barcode line
  46. *     Revision:03-Jul-91 Initial Release
  47. procedure PostalBC_Line
  48. parameter bar_code
  49. private i, length
  50.  
  51. length = len( bar_code )                  && number of lines to print
  52. i = 1                                     && first line
  53. do while ( i <= length )                  && while lines
  54.    if ( substr( bar_code, i, 1 ) = "1" )  && if long line
  55.       ?? chr(27) + "*c5a40b0P"
  56.    else                                   && short line
  57.       ?? chr(27) + "*p+22Y" + chr(27) + "*c5a18b0P" + chr(27) + "*p-22Y"
  58.    endif
  59.    ?? chr(27) + "*p+15X"                  && position of next line
  60.    i = i + 1                              && next line
  61. enddo
  62.  
  63. return
  64.